<template>
  <div class="set-header">
    <div class="set-header-back" @click="goBack()">
      <van-icon name="arrow-left" />
    </div>
    <span class="set-header-title">{{message}}</span>
    <van-popover placement="bottom-end" v-model="showPopover" trigger="click" :actions="actions" @select="onSelect">
      <template #reference>
        <van-icon class="set-header-ellipsis" name="ellipsis" />
      </template>
    </van-popover>
  </div>
</template>

<script>
  export default {
    // name: BackTitle,
    props: ['message'],
    data() {
      return {
        showPopover: false,
        actions: [{
          text: '首页'
        }, {
          text: '购物车'
        }, {
          text: '我的'
        }]
      }
    },
    methods: {
      goBack() {
        this.$router.go(-1)
      },
      onSelect(action) {
        if (action.text === '首页') {
          this.$router.push({
            path: '/Home'
          })
        } else if (action.text === '购物车') {
          this.$router.push({
            path: '/Cart'
          })
        } else {
          this.$router.push({
            path: '/Me'
          })
        }
      }
    }
  }
</script>

<style scoped>
  .set-header {
    display: flex;
    justify-content: space-around;
    background-color: #FFFFFF;
    height: 44px;
    font-size: 16px;
    text-align: center;
    color: #333;
    align-items: center;
    border-bottom: 1px solid #DDDDDD;
  }

  .set-header-title {
    width: 300px;
  }
</style>
